<template>
	<view class="content">
		<view class="box">
			<view class="input-list">
				<input placeholder="输入手机号" placeholder-class="placeholder-class" type="text" v-model="formData.phone" />
			</view>
			<view class="input-list">
				<input placeholder="请输入密码" placeholder-class="placeholder-class" type="password"
					v-model="formData.password" />

			</view>
			<view class="login-btn" @click="codeLogin">
				登录
			</view>
		</view>
	</view>
</template>

<script>
	import util from "@/utils/util.js";
	import {
		loginUserPassword
	} from "@/request/api.js";
	export default {
		components: {

		},
		data() {
			return {
				statusBarHeight: '',
				formData: {
					phone: '',
					password: '',
				}
			}
		},
		onLoad() {},
		methods: {
			async codeLogin() {
				var regExp = /^1[3456789]\d{9}$/;
				let that = this;
				let {
					phone,
					password
				} = this.formData
				if (!password) {
					uni.showToast({
						icon: '密码不能为空!',
						icon: 'none'
					})
					return;
				} else if (!phone || !regExp.test(phone)) {
					uni.showToast({
						title: "请输入正确的手机号码!",
						icon: "none"
					})
					return;
				}
				
				let r = await uni.login();
				
				let res = await loginUserPassword({
					method: "get",
					data: {...this.formData,codeForOpenId:r.code}
				});
				
				if (res.code == 200) {
					let {
						token,
						phoneNumber
					} = res.data;
					uni.setStorageSync('token', token);
					uni.setStorageSync('userInfo', res.data);
					uni.setStorageSync('tokenExp', util.getTokenExp())
					uni.showToast({
						title: "登录成功",
						icon: "success",
					});
					// 绑定邀请人id
					// util.sendSharedUserIdFn();
					setTimeout(()=>{
						uni.navigateBack(-1)
					},500)
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}

			},
			//第三方授权 ##微信 QQ 微博
			thirdPartyAuth(loginType) {

			},
		}
	}
</script>

<style>
	.content {
		background: linear-gradient(to bottom, #ec6025 1.52%, #fff 30.65%);
		/* padding-top:500rpx; */
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;

	}

	.bg-image {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 1472rpx;
		z-index: -1;
	}

	.header {
		font-size: 66rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
		color: #eb5b1e;
		padding: 0 85rpx;
		display: flex;
		flex-direction: column;
		margin: 110rpx 0 60rpx 0;
	}

	.header text:nth-child(2) {
		font-size: 43rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
	}

	.input-list {
		display: flex;
		justify-content: space-between;
		padding: 0 60rpx;
		height: 100rpx;
		border-bottom: 1rpx solid #aaa;
		align-items: center;
	}

	.code-view {
		width: 156rpx;
		height: 61rpx;
		border: 2rpx solid #eb5b1e;
		border-radius: 7rpx;
		line-height: 61rpx;
		text-align: center;
		font-size: 26rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
		color: #eb5b1e;
	}

	.placeholder-class {
		font-size: 27rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
		color: #B3B3B3;
	}

	.login-btn {
		width: 646rpx;
		height: 95rpx;
		background: #eb5b1e;
		/* box-shadow: 0rpx 0rpx 19rpx 1rpx rgba(106, 225, 198, 0.6); */
		border-radius: 48rpx;
		line-height: 95rpx;
		text-align: center;
		font-size: 29rpx;
		font-family: Source Han Sans SC;
		font-weight: bold;
		color: #FFFFFF;
		margin: 78rpx auto 0;
	}

	.third-party-login {
		display: flex;
		justify-content: space-around;
		text-align: center;
		margin-top: 94rpx;
	}

	.third-party-login .list image {
		width: 95rpx;
		height: 95rpx;
		border-radius: 50%;
		display: block;
		margin: 0 auto 25rpx;
	}
</style>